;MsgBox(64, "smerfe", "Please view the Readme.txt before running this fishing bot.")
#Tidy_Parameters = /pr 1 /tc 0 /gd 0 /rels 1 /sci 1
Opt("WinTitleMatchMode", 3)
#include <GUIConstants.au3>
#Include <Misc.au3>
Global $SetWin = 0, $Loop = 0, $OldSelect, $Casted = 0, $Sec = 28, $Timer, $SLeft, $SRight, $STop, $SBottom, $WS_EX_CLIENTEDGE, $ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY, $WS_VSCROLL
Global $Splash = 0xF6F6F6, $Red = -1

Global $FishGUI = GUICreate("beware of the zulu", 225, 350)
GUISetFont(9, 800, 0, "MS Sans SerIf")
GUISetBkColor(0xA6CAF0)
Global $RedPreview = GUICtrlCreateLabel("Please Select A Color!", 10, 265, 100, 75, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor($RedPreview, -1)
Global $SplashPreview = GUICtrlCreateLabel("", 115, 265, 100, 75, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetBkColor($SplashPreview, $Splash)
Global $ColorSelect = GUICtrlCreateCombo("", 10, 240, 205, 25)
GUICtrlSetData($ColorSelect, IniRead("Colors.ini", "Standard", "List", Default))
GUICtrlSetColor($ColorSelect, 0x800080)
Global $WindowDisplay = GUICtrlCreateInput("Window Not Found", 10, 10, 205, 20, BitOR($ES_CENTER, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetColor($WindowDisplay, 0x800080)
Global $Start = GUICtrlCreateButton("Start", 10, 35, 100, 25, 0)
Global $STop = GUICtrlCreateButton("Stop", 115, 35, 100, 25, 0)
Global $Stats = GUICtrlCreateEdit("Statistics", 10, 65, 205, 170, BitOR($ES_READONLY, $WS_VSCROLL))
GUISetState(@SW_SHOW)
Global $MaxTime = $Sec * 10000
Global $Lite = ObjCreate("SERFLITEMAX20.Core.Main")
 
$Lite.StartFishing
sleep(5000)
Global $buffer = 0.095
Global $PlayerFacing = $Lite.PlayerFacing
While 1
	GUI()
	Sleep(5)
WEnd
GUIDelete($FishGUI)
Exit
Func Bot()
	;Local $FeedPet = false
	Sleep(10000);
	
	WinActivate("World of Warcraft")
	WinWaitActive("World of Warcraft")
	Sleep(3000)
	Local $WindowPosition = WinGetPos("World of Warcraft")
	Local $BHeight = 23
	Local $BWidth = 4
	$ScreenSize = WinGetClientSize("World of Warcraft")
	ReDim $ScreenSize[4]
	$ScreenSize[2] = $WindowPosition[0] + $BWidth
	$ScreenSize[3] = $WindowPosition[1] + $BHeight
	$Top = $ScreenSize[3] + (.15 * $ScreenSize[1])
	$Bottom = $Top + (.40 * $ScreenSize[1]) - 1
	$Left = $ScreenSize[2] + (.05 * $ScreenSize[0])
	$Right = $Left + $ScreenSize[0] - (.10 * 2.0 * $ScreenSize[0]) - 1
	MouseMove($Left, $Top, 2)
	MouseMove($Right, $Top, 2)
	MouseMove($Right, $Bottom, 2)
	MouseMove($Left, $Bottom, 2)
	$count = 0;
	
	;anti afk
	Send("{SPACE}")
	Sleep(3000)
	Send("^{NUMPADMULT}")
 
	;cast first lure on pole (activate macro)
	Send("8")
	Sleep(11500)
		
	;lure buff time limit until rebuff
	$castit = TimerInit()
	$castinterval = 60000 * 10
	$printscreenit = TimerInit()
	$printscreeninterval = 60000 * 60
	$running = TimerInit()
	$runninginterval = 60000 * 60 * 5
	$total = 0
	$emote = 0
	
	Do
		While $Loop = 1
			
			dim $points = $Lite.CalcTurnAmount($PlayerFacing,$Lite.PlayerFacing)
			
			if $points > $buffer Then
				FixFacing($PlayerFacing)
			endif
			
			Send("^{NUMPADMULT}")
			
			$total = $total + 1
			
			$Timer = TimerInit()
			
			if $Lite.TakeScreenShot Then
				TakeScreenShot()
				sleep(3000);
			endif
			
			if TimerDiff($printscreenit) > $printscreeninterval then
				TakeScreenShot()
				sleep(3000);
				$printscreenit = TimerInit()
			endif
					
			;cast lure on pole (activate macro)
			if TimerDiff($castit) > $castinterval then
			
				Sleep(1000)
				Send("0")
				Sleep(1000)
				Send("8")
				Sleep(12500)
				$castit = TimerInit()
			endif

			;increment run count
			$count = $count + 1
			
			;every 15 cycles activate anti afk
			If $count = 15 then
				$count=0
				Send("{SPACE}")
				Sleep(1000)
			EndIf
			
 			;Sleep(500)
			;move mouse to corner
			MouseMove(0, 0, 0)
			
			;feed pet
			
			Send("3")
			Sleep(100)
			Send("6")
			Sleep(100)
			Send("4")
			Sleep(100)
			Send("5")
			Sleep(100)
			Send("7")
			;cast fishing line
			Sleep(100)
			Send("1")
			Sleep(3000)
			
			

			$checktime = TimerInit()
			
			;search for bobber
			Do
				GUI()
				Sleep(5)
				$BobberPos = PixelSearch($Left, $Top, $Right, $Bottom, $Red, 10, 3)
				if not IsArray($BobberPos) Then
					$BobberPos = PixelSearch($Left, $Top, $Right, $Bottom, $Red, 10, 3)
				endif
			;if bobber is still valid or bobber position not identified or timer has not exceeded 20 seconds
			;then continue to loop search for bobber
			Until Not $Lite.BobberValid or IsArray($BobberPos) or TimerDiff($checktime) > 10000
		
			If IsArray($BobberPos) Then
				;if bobber found then move mouse over bobber
				MouseMove($BobberPos[0], $BobberPos[1], 5)
				$SLeft = $BobberPos[0] - 35
				$SRight = $SLeft + 60
				$STop = $BobberPos[1] - 35
				$SBottom = $STop + 65
				sleep(2000)
			
				;check wow api for bobber
				If $Lite.BobberValid then
					$checktime = TimerInit()
					
					Do
						GUI()
						Sleep(5)
											
						if $Lite.BobberValid then
							;check wow api for bobber bopping
							If $Lite.Bobber.Bobbing Then
								;check make sure your not gonna attack something
								;if Not $Lite.HasTarget then
								;click bobber 3 times to catch fish
								if IsArray($BobberPos) then
									Sleep(5)
									MouseClick("right", $BobberPos[0], $BobberPos[1], 1, 0)
									sleep(350)
									MouseClick("right", $BobberPos[0], $BobberPos[1], 1, 0)
									Sleep(350);
									MouseClick("right", $BobberPos[0], $BobberPos[1], 1, 0)
									Sleep(1000);
								endif
									
								;Else
								;	Send("{ESCAPE}")
								;EndIf
								
								ExitLoop
								
							EndIf
						Else
							ExitLoop
						EndIf
					;if bobber is valid and timer did not exceed 20 seconds then continue to wait for bobber to bop
					Until Not $Lite.BobberValid  or TimerDiff($checktime) > 20000			
				EndIf
			
			EndIf
		WEnd
	Until $Loop = 0
EndFunc   ;==>Bot

func TakeScreenShot()
	Send("{SHIFTDOWN}B")
	Sleep(500)
	Send("{SHIFTUP}")
	Sleep(1000)
	Send("{PRINTSCREEN}")
	Sleep(1000)
	Send("{SHIFTDOWN}B")
	Sleep(500)
	Send("{SHIFTUP}")
endfunc

Func Window()
	Local $Old = $SetWin
	Select
		Case WinExists("World of Warcraft") And WinGetProcess("World of Warcraft") = ProcessExists("WoW.exe")
			$SetWin = 1
		Case Else
			$SetWin = 0
	EndSelect
	Select
		Case $Old = $SetWin
			; Do Nothing (Window has not changed)
		Case $SetWin = 0
			GUICtrlSetData($WindowDisplay, "")
			GUICtrlSetData($WindowDisplay, "Window Not Found")
		Case $SetWin = 1
			GUICtrlSetData($WindowDisplay, "")
			GUICtrlSetData($WindowDisplay, "FOUND : " & WinGetTitle("World of Warcraft"))
	EndSelect
EndFunc   ;==>Window

Func CheckTimer($PixelError)
	If TimerDiff($Timer) >= $MaxTime Then
		SetError(0)
		Return -1
	EndIf
	SetError($PixelError)
EndFunc   ;==>CheckTimer

Func GUI()
	Local $Msg = GUIGetMsg()
	Select
		Case $Msg = $GUI_EVENT_CLOSE
			;MsgBox(0, "Exit...", "Thank you for using World of Warcraft Fisher!")
			GUIDelete($FishGUI)
			Exit
		Case _IsPressed("1B") And $Loop = 1 Or $Msg = $STop And $Loop = 1
			$Loop = 0
			WinActivate("beware of the zulu")
			WinWaitActive("beware of the zulu")
			MsgBox(0, "World of Warcraft", "Fisher has stopped.")
		Case $Msg = $Start And $Loop = 0
			$Loop = 1
			Select
				Case $Red = -1
					MsgBox(16, "Error", "Please select a color first.")
				Case Else
					Bot()
			EndSelect
		Case $OldSelect <> GUICtrlRead($ColorSelect) And $Msg = $ColorSelect
			$OldSelect = GUICtrlRead($ColorSelect)
			GUICtrlSetBkColor($RedPreview, IniRead("Colors.ini", "Standard", $OldSelect, -1))
			GUICtrlSetData($RedPreview, "")
			$Red = IniRead("Colors.ini", "Standard", $OldSelect, -1)
	EndSelect
	Window()
EndFunc   ;==>GUI

func FixFacing($facing)
 
	dim $next = $Lite.PlayerFacing;
	dim $direction = $Lite.CalcDirection($facing,$next)
	dim $points = $Lite.CalcTurnAmount($facing,$next)
	dim $moveCount = 0
	dim $status = true
	
	while $status

		if ($direction = "SAME") Then
			$status = False
		endif
		if ($points < $buffer) then
			$status = $status and False
		endif
		 
		 ;msgbox(0, $status, $status )
		if $status then
			if $direction = "LEFT" Then
				$moveCount = Floor($points / 0.06)
				while $moveCount > 0
					send("aaa")
					sleep(60)
					$moveCount = $moveCount - 1
				wend
			endif
			if $direction = "RIGHT" Then
				$moveCount = Floor($points / 0.06)
				while $moveCount > 0
					send("ddd")
					sleep(60)
					$moveCount = $moveCount - 1
				wend
			endif
			
			$next = $Lite.PlayerFacing
			$direction = $Lite.CalcDirection($facing,$next)
			$points = $Lite.CalcTurnAmount($facing,$next)
			
		endif
	wend
endfunc